use crate::{connection::ConnectionState, resp};

pub(crate) fn build_hello_command(state: &ConnectionState) -> resp::Command {
    let mut cmd_hello = resp::Command::new("HELLO");
    cmd_hello.arg_append(3u8);
    if let Some(client_name) = state.client_name.as_ref() {
        cmd_hello.arg_append("SETNAME").arg_append(client_name);
    }
    if let Some(username) = state.user.as_ref() {
        cmd_hello.arg_append("AUTH").arg_append(username);
    }
    if let Some(password) = state.password.as_ref() {
        if state.user.is_none() {
            cmd_hello.arg_append("AUTH").arg_append("default");
        }
        cmd_hello.arg_append(password);
    }
    cmd_hello
}

#[allow(dead_code)]
#[derive(serde::Deserialize, Debug)]
pub(crate) struct HelloResponse {
    pub server: String,
    pub version: String,
    pub proto: u8,
    pub id: u32,
    pub mode: String,
    pub role: String,
    pub modules: Vec<ModuleInfo>,
}

#[allow(dead_code)]
#[derive(serde::Deserialize, Debug)]
pub(crate) struct ModuleInfo {
    pub name: String,
    pub ver: i32,
    pub path: String,
    pub args: Vec<String>,
}
